package com.xinongbest.mall.util;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class ZKClient implements Watcher {
    public static final String SERVER_PATH = "10.1.1.181:2181,10.1.1.181:2182";

    public static final Integer TIMEOUT = 5000;

    public static void main(String[] args) throws IOException, InterruptedException {
        ZooKeeper zk = new ZooKeeper(SERVER_PATH, TIMEOUT, new ZKClient());
        System.out.println("客户端开始连接ZK服务器");
        System.out.println(zk.getState());
        Thread.sleep(2000);
        System.out.println(zk.getState());
    }

    @Override
    public void process(WatchedEvent watchedEvent) {
        System.out.println("收到通知" + watchedEvent);
    }
}
